<?php
/*
*  edited by cbq in 2016.03.16
*  新建MY_Controller类，重写smarty中的assign方法和display方法
*/
if (!defined('BASEPATH')) exit('No direct access allowed.');
class MY_Controller extends CI_Controller {
    protected $_URL;
    protected $_URLLOGIN;
    protected $menuaArr=array();//菜单列表
    protected $siteColumnArr=array();//栏目权限
    public function __construct(){
        parent::__construct();
        //加载session类
        $this->load->library('session');
        //加载记录操作行为类
        $this->load->model('adminuserRecord_m');
        //加载js 类
        $this->load->library('Js');
        //加载公共配置文件
        load_confog(_CONFIG);
        $this->assign('getConfig',getConfig());
        //站点url;
        $this->_URL=base_url();
        //后台登陆页面
        $this->_URLLOGIN=$this->_URL."Login/index";
        $this->assign('_URL',$this->_URL);
    }

    public function assign($key,$val){
        $this->cismarty->assign($key,$val);
    }
    public function display($html){
        $this->cismarty->display($html);
    }
    public function fetch($html){
        return $this->cismarty->fetch($html);
    }
    //session 用户验证
    public function sess_checked(){
        if(!isset($_SESSION['eduadmininfo'])){
            echo Js::top_to_url($this->_URLLOGIN);exit;
        }
        $eduadmininfo=unserialize($_SESSION['eduadmininfo']);
        $this->assign('token',$eduadmininfo['usertoken']);
        $this->assign('name',$eduadmininfo['displayname']);
        //powerlist=json_encode(array('menu'=>array(),'siteColumn'=array(array('siteid'=>$siteid,'columnid'=array()))))
    }
    //菜单权限设置
    public function menuauth(){
        $eduadmininfo=unserialize($_SESSION['eduadmininfo']);
        //获取所有菜单列表
        $menulist=getConfig('menu');
        if($eduadmininfo['issysadmin']==1){//系统管理员
            $this->menuArr=$menulist;
        }else{//其他权限用户
            $menuarr=array();
            $powerlist=json_decode($eduadmininfo['powerlist'],true);
            $menu_arr=$powerlist['menu'];
            foreach($menuresult as $k=>$v){//菜单权限获取
                if(in_array($v['id'],$menu_arr)){
                    $this->menuArr[]=$v;
                }
            }
            if(empty($this->menuarr)){
                echo Js::alert('菜单无权限');
                echo Js::top_to_url($this->_URLLOGIN);exit;
            }
        }
    }
    /**
     * return ture表示超级管理员 ;false:其他管理员  栏目权限值为$this->siteColumnArr;
     * @return [type] [description]
     */
    public function columnauth(){
        $eduadmininfo=unserialize($_SESSION['eduadmininfo']);
        if($eduadmininfo['issysadmin']==1){
            //获取所有栏目列表
            return true;
        }else{
            $powerlist=json_decode($eduadmininfo['powerlist'],true);
            if(empty($powerlist['siteColumn'])){
                echo Js::alert('无栏目权限');
                echo Js::top_to_url($this->_URLLOGIN);exit;
            }
            $this->siteColumnArr=$powerlist['siteColumn'];
            return false;
        }
    }
    protected function error_msg($msg){
        if(isset($_POST['ajaxs'])){
            ajax_return(0,$msg);
        }else{
            echo Js::alert($msg);exit;
        }
    }
}
?>
